package com.zklh.leetcode.interviewTop150;

/**
 * 买卖股票的最佳时机II
 */
public class Solution122 {
    public int maxProfit(int[] prices) {
        int current = 0;
        int maxProfit = 0;
        while (current < prices.length) {
            int handle = current++;
            while (current < prices.length && prices[current] >= prices[current-1]) {
                current++;
            }
            maxProfit += (prices[current-1] - prices[handle]);
        }
        return maxProfit;
    }
}
